<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="format-detection" content="telephone=no">
    <title>{$region['title']}</title>
    <link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/style/style1/static/css/style.css" />
    <link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/style/style1/static/css/home.css" />
    <link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/style/style1/static/css/header.css" />
    <script type="text/javascript" src="{MODULE_URL}template/mobile/style/style1/static/js/zepto.js"></script>
</head>

<body class="bg-f2">
    <div id="not-share-top">
        <div class="index-top" style="margin-top:-16px;">
            <!-- 20150504-头部-start -->
            <header id="header">
                <div class="header_div">
                    <div id="left_div" onClick="javascript:history.back();"></div>
                    <div id="middle_div">
                        <h1 id="title">商品详情</h1></div>
                    <div id="right_div">
                        <div class="right_bottom"></div>
                        <div class="right_img"></div>
                    </div>
                </div>
            </header>
            <!-- 20150504-头部-start -->
        </div>
        <div class="hr-150-1"></div>
    </div>
    <section class="pro-property">
        <!-- 20150605-图片轮播-start -->
        <div id='slider' class='swipe' style="margin-top:10px;">
            <div class='swipe-wrap'>
                {if empty($piclist)}
                <div class='wrap'>
                    <a href="#" style="text-align:center;list-style: none;display:block">
                        <img src="{php echo tomedia($goods['thumb'])}" height='160px' />
                    </a>
                </div>
                {else} {loop $piclist $row}
                <div class='wrap'>
                    <a href="#" style="text-align:center;list-style: none;display:block">
                        <img src="{$row}" height='160px' />
                    </a>
                </div>
                {/loop} {/if}
            </div>
        </div>
        <!-- 20150605-图片轮播-end -->
        <article class="pro-meta-area" style="padding-bottom: 0.5em;">
            <h3 id="simpleDesc">{$goods['title']}</h3>
            <div class="pro-price">
                <span class="p-price-now">
                            <b>¥<i id="discount_price">{$marketprice}</i>
                                <span>{$goods['unit']}</span>
                </b>
                </span>
                <span id="market_price" class="p-price-cost">{$productprice}</span>
                
                <p style="font-size: 1.2em;color: #999;margin-top:2px;">赠送积分：<span><b id="discount_sum" style="color: #e4393c;font-size: 1.2em;">{$goods['credit']}</b></span>&nbsp;&nbsp;&nbsp;
                <span id="market_price" >库存{$stock}</span>
                </p>
            </div>
        </article>
        <!--     <a syle="margin: 20%;" id="receiveGiving"> 送礼</a> -->
        <div id="goods_spec">
            <article class="pro-type">
                <div style="color: #4d525d; font-size: 1.2em; margin:0 0.8em; line-height: 4.5em; float:left;">数量：</div>
                <div class="option1" style="float:left; margin-top:1.5em; font-size:0.9em;">
                    <label class="btn-del" onclick="reduceNum()"></label>
                    <input id="total" type="text" value="1" onkeyup="value=value.replace(/[^\d]/g,'')">
                    <label class="btn-add" onclick="addNum()"></label>
                </div>
            </article>
            <input id="goodNum" type="hidden" value="100">
        </div>
        <article class="pro-meta-content">
            <h3 class="pro-meta-content-h3">商品详情</h3>
            <div class="pro-meta-content-div">
                {$goods['content']}
            </div>
        </article>
    </section>
    <footer class="pro-footer">
        <a class="pro-footer-car" id="shopCart" onclick='addtocart()'>加入购物车</a>
        <a class="pro-footer-buy" id="buy" onclick='buy()'>立即购买</a>
    </footer>
    <div class="layer"></div>
    <a href="javascript:window.location.href='{php echo $this->createMobileUrl('shopping',array('op' => 'mycart'))}';" class="footer-car" id="counts" style="display: inline;"><span id="carttotal">{$carttotal}</span></a>
    <script type="text/javascript">
    //增加数量
    function addNum() {
        var total = $("#total");
        // if(!total.isInt()){
        //  total.val("1");
        // }
        var stock = $("#stock").html() == '' ? -1 : parseInt($("#stock").html());
        // var mb = maxbuy;

        // if(mb>stock && stock!=-1){
        //  mb = stock;
        // }
        var num = parseInt(total.val()) + 1;
        if (num > stock) {
            tip("您最多可购买 " + stock + " 件!", true);
            num--;
        }
        // if(num>mb && mb>0){
        //  tip("您最多可购买 " + mb + " 件!",true);
        //  num = mb;
        // }
        total.val(num);
    }
    //减少数量
    function reduceNum() {
        var total = $("#total");
        // if(!total.isInt()){
        //  total.val("1");
        // }
        var num = parseInt(total.val());
        if (num - 1 <= 0) {
            return;
        }
        num--;
        total.val(num);
    }
    //添加到购物车
    function addtocart() {
        // var ret = option_selected();
        //alert(ret.no);return false;
        // if(ret.no!=''){
        //  tip("请选择" + ret.no + "!",true);
        //  return;
        // }
        // tip("正在处理数据...");
        var total = $("#total").val();
        var stock = parseInt($('#stock').text());
        if (stock == 0) {
            tip('库存不足，无法购买。');
            return;
        }
        //alert(total);
        //var url = "{php echo murl('entry//shopping',array('op' => 'mycart','id'=>$goods['id'],'operation'=>'add','m'=>'xfeng_community'),true)}"+"&optionid=" + $("#optionid").val() + "&total=" + total;
        var url = "{php echo $this->createMobileUrl('shopping',array('op' => 'mycart',id => $goods['id'],'operation' =>'add'),'',true)}" + "&total=" + total;
        //  var url = '{php echo $this->createMobileUrl('mycart',array('op'=>'add','id'=>$goods['id']),true);}' +"&optionid=" + $("#optionid").val() + "&total=" + total;
        $.getJSON(url, function(s) {
            //alert(s);return false;
            if (s.result == 0) {
                alert("只能购买 " + s.maxbuy + " 件!");
                return;
            } else {

                $("body").append("<div class='added' style='z-index:99999;'><p>已加入购物车<p></div>");
                $('#carttotal').html(s.total);
            }
            setTimeout(function() {
                window.location.reload();
            }, 300);
        });
    }
    //购买
    function buy() {
        // var ret = option_selected();
        //  if(ret.no!=''){
        //     tip("请选择" + ret.no + "!",true);
        //      return;
        //  }
        var stock = parseInt($('#stock').text());
        if (stock == 0) {
            //tip('库存不足，无法购买。');
            $("body").append("<div class='added' style='z-index:99999;'><p>库存不足，无法购买。<p></div>");
            setTimeout(function() {
                window.location.reload();
            }, 300);
            return;
        }
        var total = $("#total").val();
        //location.href ="{php echo murl('entry//confirm',array('id'=>$goods['id'],'op'=>'confirm','m'=>'ewei_shopping'),true)}"+"&optionid=" + $("#optionid").val() + "&total=" + total;
        location.href = "{php echo $this->createMobileUrl('shopping',array('op' => 'confirm','id'=>$goods['id']),true)}" + "&total=" + total;
    }
    </script>
    <script type="text/javascript" src="{MODULE_URL}template/mobile/style/style1/static/js/swipe.js"></script>
    <script>
    $(function() {
        new Swipe($('#slider')[0], {
            speed: 500,
            auto: 3000,
            callback: function() {
                var lis = $(this.element).next("ol").children();
                lis.removeClass("on").eq(this.index).addClass("on");
            }
        });
    });
    </script>
</body>

</html>
